package com.njitzx.service.impl;

import com.njitzx.entity.po.Consignee;
import com.njitzx.mapper.ConsigneeMapper;
import com.njitzx.service.ConsigneeService;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.io.Serializable;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


/**
 * <p>
 * 收货人表 服务实现类
 * </p>
 *
 * @author 周鑫
 * @since 2024-08-20
 */
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class ConsigneeServiceImpl implements ConsigneeService {

    private final ConsigneeMapper consigneeMapper;

    /**
     * 收货人表分页查询
     * @param pageNum
     * @param pageSize
     * @param consignee
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public PageInfo<Consignee> findPage(Integer pageNum, Integer pageSize, Consignee consignee) {
        PageHelper.startPage(pageNum,pageSize);
        List<Consignee> consigneeList = consigneeMapper.select(consignee);
        return new PageInfo<>(consigneeList);
    }

    /**
     * 根据主键查询收货人表
     * @param consId
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public Consignee findById(Serializable consId) {
        return consigneeMapper.selectById(consId);
    }

    /**
     * 收货人表新增
     * @param consignee
     */
    @Override
    public void add(Consignee consignee) {
        consigneeMapper.insert(consignee);
    }

    /**
     * 修改收货人表
     * @param consignee
     */
    @Override
    public void modify(Consignee consignee) {
        consigneeMapper.update(consignee);
    }

    /**
     * 根据主键删除收货人表
     * @param consId
     */
    @Override
    public void removeById(Serializable consId) {
        if(((String)consId).contains(",")){
            consigneeMapper.deleteByIds(((String)consId).split(","));
        }else {
            consigneeMapper.deleteById(consId);
        }
    }
}
